function Add-PartialBranchGitClone {
<#
.SYNOPSIS
Clones a GIT repository from a TFS server path

.DESCRIPTION
This is intended to be the git clone of the partial branch creatred by Add-PartialBranch. It uses git-tf to clone the TFS server path specified in the Branch argument to a git repository located at the path specifile in the LocalSourcePath argument. If a RemoteOrigin argument is provided, a origin Remote is added to the repository pointing to the path given in that parameter. A bare git repo of the repo just created is then cloned to that path. Autocrlf is set to false and ignorecase is set to true. If a NonVolatile workspace was created using Add-NonVolatileEnlistment then its directories are symbolicaly linked and an excludes file is added to .git\info for those directories.

.PARAMETER TfsUrl
The TFS Collection URL to use for connecting to TFS

.PARAMETER Branch
The TFS Serverpath to be cloned

.PARAMETER LocalSourcePath
Local path where the git repository will reside

.PARAMETER RemoteOrigin
Path where a bare repository will be cloned to and added as the origin Remote. If a http or git:// based URI is enterd, the repo will not be cloned, instead the uri will simply be added as the remote origin.

.EXAMPLE
Add-PartialBranchGitClone -tfsUrl http://myserver:8080/tfs -branch $/my/branch -localSourcePath "c:\dev\src\" -RemoteOrigin \\server\share\repo

This will create a git repository of $my/branch located at c:\dev\src and the repo will be cloned to \\server\share\repo. All git pushes and pulls will be directed tothat remote location.

.LINK
https://BigGit.Codeplex.com
Add-PartialBranch
Add-NonVolitileEnlistment
#>        
    param(
            [Parameter(Mandatory=$true)]
            [string] $tfsUrl, 
            [Parameter(Mandatory=$true)]
            [string] $branch, 
            [Parameter(Mandatory=$true)]
            [string] $localSourcePath, 
            [string] $remoteOrigin
    )
    Write-BigGitMessage "Creating Git repo of $branch at $localSourcePath"  -backgroundColor darkgreen
    if(Test-Path "$localSourcePath\.git") {
        pushd "$localSourcePath"
        $gitTfConfig = @{}
        git-tf config | % { 
            $keyval = $_.Split(':',2)
            if($keyval -and $keyval.Count -gt 1){
                $gitTfConfig.$($keyval[0].Trim())=$keyval[1].Trim()
            }
        }
        popd
        if($gitTfConfig["TFS Server Path"] -and $gitTfConfig["TFS Server Path"].ToLower() -ne $branch) {
            throw "A git repository already exists at $localSourcePath and is mapped to $($gitTfConfig['TFS Server Path'])"
        }
        throw "A git repository already exists at $localSourcePath"
    }
    git-tf clone $tfsUrl $branch $localSourcePath
    $currentDirectory = resolve-path .
    try {
        if(!(Test-Path $localSourcePath\.git)) {
            throw "Unable to create git repository"
        }
        set-location $localSourcePath
        Write-BigGitMessage "Configuring git"  -backgroundColor darkgreen
        git config --global core.autocrlf false
        git config --global core.ignorecase true
        #git config --global core.preloadindex true
        if(!(Test-Path ".\.git\info")) {mkdir ".\.git\info" | out-null}
        $nonVolatile = Get-BigGitConfig "NonVolatilePath"
        if($nonVolatile){
            Set-NonVolatileLinks $nonVolatile
            Write-BigGitMessage "Adding directories for git to ignore" -backgroundColor darkgreen
            Get-ChildItem $nonVolatile | % { $_.name } | set-content ".\.git\info\exclude" | out-host
        }
        Set-BigGitConfig "GitRepoPath" (resolve-path .).Path
        if($remoteOrigin){
            if($remoteOrigin.ToLower().StartsWith("http") -or $remoteOrigin.ToLower().StartsWith("git://")){
                $origin = $remoteOrigin
            } else {
                $origin = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($remoteOrigin)
                if(!(Test-Path "$origin\.git")) {
                    Write-BigGitMessage "cloning bare repo to remote origin $origin" -backgroundColor darkgreen
                    git clone --bare . $origin
                }
            }
            git remote add origin $origin.Replace("\","/")
        }
    } finally {set-location $currentDirectory}
}